home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / icmpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-07  |  1.7 KB  |  71 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "internet.h"
  6. #include "netuser.h"
  7. #include "icmp.h"
  8. #include "trace.h"
  9. #include "ip.h"
  10.  
  11. /* Dump an ICMP header */
  12. void
  13. icmp_dump(fp,bpp,source,dest,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int32 source,dest;
  17. int check;        /* If 0, bypass checksum verify */
  18. {
  19.     struct icmp icmp;
  20.     int16 csum;
  21.  
  22.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  23.         return;
  24.  
  25.     csum = (check == 1) ? cksum(NULLHEADER,*bpp,len_p(*bpp)) : 0;
  26.  
  27.     ntohicmp(&icmp,bpp);
  28.     textattr(LIGHTMAGENTA);
  29.     trprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  30.     
  31.     switch(uchar(icmp.type)){
  32.     case ICMP_DEST_UNREACH:
  33.         trprintf(fp," code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  34.         break;
  35.     case ICMP_REDIRECT:
  36.         trprintf(fp," code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  37.         trprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  38.         break;
  39.     case ICMP_TIME_EXCEED:
  40.         trprintf(fp," code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  41.         break;
  42.     case ICMP_PARAM_PROB:
  43.         trprintf(fp," pointer %u",icmp.args.pointer);
  44.         break;
  45.     case ICMP_ECHO:
  46.     case ICMP_ECHO_REPLY:
  47.     case ICMP_INFO_RQST:
  48.     case ICMP_INFO_REPLY:
  49.     case ICMP_TIMESTAMP:
  50.     case ICMP_TIME_REPLY:
  51.         trprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  52.         pullup(bpp,NULLCHAR,sizeof(int32));
  53.         break;
  54.     }
  55.     if(csum)
  56.         trprintf(fp," CHECKSUM ERROR (%u)",csum);
  57.     trprintf(fp,"\n");
  58.  
  59.     /* Dump the offending IP header, if any */
  60.     switch(icmp.type){
  61.     case ICMP_DEST_UNREACH:
  62.     case ICMP_TIME_EXCEED:
  63.     case ICMP_PARAM_PROB:
  64.     case ICMP_QUENCH:
  65.     case ICMP_REDIRECT:
  66.         trprintf(fp,"Returned ");
  67.         ip_dump(fp,bpp,0);
  68.     }
  69. }
  70.  
  71.